<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="Public:meta" />
</head>
<body id="main_page">
<include file="Public:position" />
<div class="container"> 
    <form enctype="multipart/form-data" method="post" id="frm">
    <input type="hidden" name="NowPage" id="NowPage" value="{$NowPage}" />
      <div class="table">
      <div class="toolbars">
            <li class="toolbar"><a id="btnSave" onclick="exportMessage()"  title="导出所有数据">导出所有数据</a></li>
            <li class="toolbar"><a id="btnSaveAll" href="{$Group}/ChannelModel/viewField/ChannelModelID/6"  title="留言字段设置">留言字段设置</a></li>
            <li class="toolbar"><a id="btnConfig" href="{$Group}/Config/guestbook"  title="设置">&nbsp;设置</a></li>
            <li class="toolbar"><a id="selectall" onclick="CheckAll()"  title="全选">全选</a></li>
            <li class="toolbar"><a id="del" onclick="BatchDel()" title="批量删除">删除</a></li>
            <li class="toolbar"><a id="btnCheck" onclick="BatchCheck(1)" title="批量审核">审核</a></li>
            <li class="toolbar"><a id="btnUnCheck" onclick="BatchCheck(0)" title="批量取消审核">取消审核</a></li>
        </div>                    
        <table class="datatable" id="datatable">
            <tr>
                <th width="35px"  nowrap="nowrap">选中</th>
                <th width="45px" >ID</th>
                <th  width="115px" >留言人</th>
                <th >内容</th>
                <th width="120px" >时间</th>
                <th width="200px" >管理员回复</th>
                <th width="60px" >是否审核</th>
                <th width="150px">操作</th>
            </tr>  
            <notempty name="Message">
                <volist name="Message" id="m">
                    <tr id="tr{$m.MessageID}">
                        <td><input class="checkrow" type="checkbox" name="MessageID[]" value="{$m.MessageID}" /></td>
                        <td>{$m.MessageID}</td>
                        <td>{$m.GuestName}
                            <eq name="m.GuestID" value="0">[&nbsp;游客&nbsp;]
                            <else/><span style="color:red">[会员]</span>
                            </eq><br/>
                            <span style="color:red;font-weight:bold">IP : {$m.GuestIP}</span>
                        </td>
                        <td style="text-align:left">{$m.AllInfo}</td>
                        <td>{$m.MessageTime|strtotime|yd_friend_date}</td>
                        <td style="text-align:left">
                            <notempty name="m.AnswerContent">
                            <span id="AnswerContent{$m.MessageID}" style="color:#060">{$m.AnswerContent}&nbsp;&nbsp;</span>
                            <br/><span style="color:red; float:right"><b style="color:#000000">回复时间：</b>{$m.AnswerTime|strtotime|yd_friend_date}</span>
                            </notempty>
                        </td>
                        <td>
                            <eq name="m.IsCheck" value="0">
                            <span style="color:#F00;cursor:pointer;"  onclick="toggleStatus(this,{$m.MessageID},'guestbook','未审核',0,'#F00','已审核',1,'#000','IsCheck')">未审核</span>
                            <else/>
                            <span style="color:#000;cursor:pointer;"  onclick="toggleStatus(this,{$m.MessageID},'guestbook','未审核',0,'#F00','已审核',1,'#000','IsCheck')">已审核</span>
                            </eq>
                        </td>
                        <td class="operator">
                            <a style="float:left" id="btnAnswer" name="btnAnswer" onclick="Answer({$m.MessageID})">回复</a>
                            <div class="btn-sep"></div>
                            <a style="float:left" onclick="Del({$m.MessageID})" class="btnDel">删除</a>
                        </td>
                    </tr>
                </volist> 
            <else/>
                <tr><td colspan="8" id="NoData">{$Think.lang.NoDataTip}</td></tr>
            </notempty>                                
        </table>
        <div class="tfoot">
        	<div class="page"><span class="pagesize">每页<span class="pz">{$AdminPageSize}</span>条</span>{$Page}</div>
        </div>
    </div>
    </form>
</div>
</body>
</html>

<div class="dialog"  id="dlgAnswer" title="管理员回复">
	<form enctype="multipart/form-data" method="post" id="frmAnswer">
	<table>
		<tr>
			<td valign="middle">
			<textarea style="width:350px;height:110px" name="dlgAnswerContent" id="dlgAnswerContent"></textarea>
			<input type="hidden" name="dlgMessageID" id="dlgMessageID" />
			<input type="hidden" name="NowPage" id="NowPage" value="{$NowPage}" />
			</td>
		</tr>
	</table>
	</form>
</div>
<script type="text/javascript">
function Del(id){
	$.confirm("{$Think.lang.DeleteTip}", function () {
		url = "{$Url}delMessage/MessageID/"+id+"/p/{$NowPage}";
		location.href = url;
	}, function () {
		return true;
	});
}

//回调函数
function DelComplete(data, textStatus){
	if (data.status == 1){
		$(data.data).css("display","none");
	}else{ 
		//删除失败
		ErrorBox(data.info);
	}
}

function Answer(id){
	var title = $("#MessageTitle"+id).html();
	$('#dlgMessageID').val(id);
	
	var content = $("#AnswerContent"+id).html();
	$('#dlgAnswerContent').html(content);
	$.dialog({
			title: "回复内容",
			id: 'answer',
			padding: 5,
			content: document.getElementById('dlgAnswer'),
			ok: function () {
				$('#frmAnswer').attr("action", "__URL__/AnswerMessage");
				$('#frmAnswer').submit();
				return true;
			},
			okValue: '确定',
			cancelValue: '关闭',
			cancel: true
		});
}

function exportMessage(){
	var url = "{$Url}exportMessage";
	location.href = url;
}

//批量删除
function BatchDel(){
	//var arrChk = $("input[name='InfoID[]'][checked]"); //在高速浏览器长度总是返回0
	var arrChk = $("input[name='MessageID[]']");
	var n = 0;
	for(var i = 0; i < arrChk.length; i++){
		if(arrChk[i].checked) n++;
	}
	
	if( n == 0 ) {
		WarnBox("{$Think.lang.CheckDeleteTip}");
		return;
	}
	
	$.confirm("{$Think.lang.DeleteTip}", function () {
		$('#frm').attr("action", "__URL__/batchDelMessage");
		$('#frm').submit();
	}, function () {
		return true;
	});
}

//批量审核
function BatchCheck(bCheck){
	//先必须选中记录==============================================
	var arrChk = $("input[name='MessageID[]']");
	var n = 0;
	for(var i = 0; i < arrChk.length; i++){
		if(arrChk[i].checked) n++;
	}
	if( n == 0 ) {
		WarnBox("请先选中记录!");
		return;
	}
	//=========================================================
	if( bCheck == 1 ){
		$.confirm("<div id='icon_common'>确定审核通过吗?</div>", function () {
			$('#frm').attr("action", "__URL__/batchCheckMessage/Check/1");
			$('#frm').submit();
		}, function () {
			return true;
		});
	}else{
		$.confirm("<div id='icon_common'>确定取消审核吗?</div>", function () {
			$('#frm').attr("action", "__URL__/batchCheckMessage/Check/0");
			$('#frm').submit();
		}, function () {
			return true;
		});
	}
}
</script>